﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RedeSocial.DataAccess;

namespace RedeSocial.ViewModels
{
	/// <summary>
	/// Class responsible for managing the resources used by the label system.
	/// </summary>
	public static class ResourceManager
	{
		#region fields...
		private readonly static object _syncObj = new object();
		#endregion
		#region properties...
		private static SortedDictionary<int, Resource> Resources { get; set; }
		#endregion
		#region methods...
		/// <summary>
		/// Gets the resource string for the given code.
		/// </summary>
		/// <param name="code">The code.</param>
		/// <returns></returns>
		public static string GetResource(string code, int languageId)
		{
			if (Resources == null)
			{
				lock (_syncObj)
				{
					if (Resources == null)
						Resources = new SortedDictionary<int, Resource>();
				}
			}
			Resource resource;

			if (Resources.ContainsKey(languageId))
				resource = Resources[languageId];
			else
			{
				resource = new Resource() { LanguageId = languageId };
				Resources.Add(languageId, resource);
			}
			return resource.GetResource(code);
		}
		#endregion
	}
}
